package com.changjiang.myproductsale.myproduct.dao.impl;

import com.changjiang.myproductsale.myproduct.dao.BaseDao;
import com.changjiang.myproductsale.myproduct.dao.CategoryDao;
import com.changjiang.myproductsale.myproduct.entity.Category;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CategoryImpl extends BaseDao implements CategoryDao {

    @Override
    public List<Category> getAllCategories() {
        String sql = "SELECT * FROM category ORDER BY category_pid";
            List<Category> categories = new ArrayList<>();
            try (Connection conn = initConnection();
                 PreparedStatement pstmt = conn.prepareStatement(sql);
                 ResultSet resultSet = pstmt.executeQuery()) {
                while (resultSet.next()) {
                    Category category = new Category(
                            resultSet.getInt("category_id"),
                            resultSet.getInt("category_pid"),
                            resultSet.getString("category_name")
                    );
                    categories.add(category);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return categories;
        }


    @Override
    public boolean save(Category category) {
        return false;
    }

    @Override
    public boolean delete(int id) {
        return false;
    }

    @Override
    public boolean update(Category category) {
        return false;
    }

    @Override
    public Category queryById(int id) {
        return null;
    }

    @Override
    public List<Category> queryAll() {
        return null;
    }
}